<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTopicTypeToMqttShopUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::connection('mysqlMQTT')->table('mqtt_shop_user', function (Blueprint $table) {
            $table->unsignedTinyInteger('connect_type')->default(\App\Support\MQTT::MQTT_CLIENT_CONNECT_SHOP)->comment('topic类型')->after('id');

            $table->dropIndex('mqtt_username');
            $table->unique(['username', 'connect_type'], 'mqtt_username');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::connection('mysqlMQTT')->table('mqtt_shop_user', function (Blueprint $table) {
            $table->dropColumn('connect_type');
        });
    }
}
